<template>
  <div class="qrcode-wrapper">
    <centerHeader/>

    <div class="qrcode-wrap">
      <div class="top-wrap">
        <div class="title_box">
          <span class="title-01">我的门店</span>
          <i class="el-icon-arrow-down"></i>
        </div>
      </div>
      <div class="picker">
        <div class="timer_box">
          <span>注册时间:</span>
          <el-date-picker
            v-model="startDate"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-MM-dd"
          ></el-date-picker>
          <span>至</span>
          <el-date-picker
            v-model="endDate"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-MM-dd"
          ></el-date-picker>
          <el-button type="danger" size="mini" round @click="query_shop2">查询</el-button>
        </div>

        <div>
          <div style="margin-top: 15px;" class="select_query">
            <el-input
              placeholder="请输入内容"
              v-model="search"
              class="input-with-select"
              style="font-size: 0.3rem;"
            >
              <el-select
                v-model="searchtype"
                slot="prepend"
                placeholder="请选择"
                style="font-size: 0.3rem;"
              >
                <el-option label="门店" value="store"></el-option>
                <el-option label="电话" value="tel"></el-option>
                <el-option label="区域" value="area"></el-option>
              </el-select>
              <el-button slot="append" icon="el-icon-search" @click="query_shop2"></el-button>
            </el-input>
          </div>

          <div class="shop_box">
            <transition name="slide-fade" class="tran_box">
              <div class="hotKey-wrap" v-if="isDetail1">
                <div class="shop_detail">
                  <i class="el-icon-close shop_close" @click="close1"></i>
                  <div class="add_clerk">
                    <div class="title">{{this.store_user_status}}门店</div>
                    <el-form
                      ref="formLabel"
                      :label-position="labelPosition"
                      label-width="80px"
                      :model="formLabel"
                    >
                      <el-form-item label="店铺名称">
                        <el-input type="text" v-model="formLabel.store_name" clearable></el-input>
                      </el-form-item>
                      <el-form-item label="手机号">
                        <el-input type="text" v-model="formLabel.store_mobile" clearable></el-input>
                      </el-form-item>
                      <el-form-item label="密码">
                        <el-input type="password" v-model="formLabel.store_password" clearable></el-input>
                      </el-form-item>
                      <el-input type="hidden" v-model="formLabel.uid" clearable></el-input>
                    </el-form>
                    <div class="submit-box">
                      <button class="submit-btn" @click="submit">确定</button>
                    </div>
                  </div>
                </div>
              </div>
            </transition>
            <transition name="slide-fade" class="tran_box">
              <div class="hotKey-wrap" v-if="isDetail">
                <div class="shop_detail">
                  <i class="el-icon-close shop_close" @click="close"></i>
                  <div class="shop_name">{{item.store_name}}</div>
                  <div class="shop_other_box">
                    <div class="shop_other">
                      <i class="el-icon-location-outline"></i>
                      {{item.store_address}}
                    </div>
                    <div class="shop_other">
                      <i class="el-icon-service"></i>
                      {{item.contact}}
                    </div>
                    <div class="shop_other">
                      <i class="el-icon-phone"></i>
                      {{item.store_contact_mobile}}
                    </div>
                    <div class="shop_other">
                      <i class="el-icon-time"></i>
                      注册时间:{{item.create_time| formatDate}}
                    </div>
                  </div>
                  <!--<div class="shop_price">
                                        <div>
                                            营业额:155555 元
                                        </div>
                  </div>-->
                </div>
              </div>
            </transition>
            <div class="shop_table_header">
              <div class="th_one">门店</div>
              <div class="th_two">电话</div>
              <!-- <div class="th_three">操作</div>-->
            </div>
            <ul class="shop_table_table" v-for="item in shoplist" :key="item.store_id">
              <li @click="showDetail(item.store_id)">
                <div class="td_one">
                  <div class="td_item_one">{{item.store_name}}</div>
                  <div class="td_item_two">
                    <i class="el-icon-location-outline"></i>
                    <span>{{item.store_address}}</span>
                  </div>
                </div>
                <div class="td_two">
                  <div class="td_item_one">{{item.store_contact_mobile}}</div>
                  <div class="td_item_two">
                    <i class="el-icon-user"></i>
                    <span>{{item.store_contact}}</span>
                  </div>
                </div>
                <!--   <div class="td_three">
                                    <div>
                                        <i class="el-icon-edit-outline" @click="edit_store(item)"></i>
                                        <i class="el-icon-delete" @click="delete_store(item)"></i>
                                    </div>

                </div>-->
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
    <div class="submit-box">
      <button class="submit-btn" @click="query_shop">下拉加载更多</button>
    </div>
    <centerFooter/>
  </div>
</template>

<script type="text/ecmascript-6">
import centerHeader from "@/views/center/components/centerHeader";
import centerFooter from "@/views/center/components/centerFooter";
import constant from "@/utils/constant.js";
import searchPrdt from "../components/search";
import { formatTime } from "@/utils/index.js";
import moment from "moment";
// 引用API文件
import http from "@/utils/http.js";

import QRCode from "qrcode";

export default {
  name: "qrcode",
  data() {
    return {
      user_info: {},
      startDate: "",
      endDate: "",
      isDetail: false,
      isDetail1: false,
      searchtype: "store",
      search: "",
      shoplist: [],
      shopDetail: {},
      item: {},
      p: 0,
      labelPosition: "left",
      formLabel: {
        store_name: "",
        store_mobile: "",
        store_password: "",
        uid: 0,
        store_id: 0
      },
      store_user_status: "新增",
      store_invite_uid: "",
      is_add: true
    };
  },
  components: {
    centerHeader,
    centerFooter,
    searchPrdt
  },
  filters: {
    formatDate(time) {
      return moment(time * 1000).format("YYYY-MM-DD");
    }
  },
  methods: {
    userinfo() {
      http.get(this, {
        url: "ucenter/user_info",
        data: {
          token: localStorage.getItem("user_token")
        },
        dataType: "json",
        success: function(data) {
          console.log("用户信息:", data);
          if (data.status == 1) {
            this.user_info = data.info;
            // 获取页面的canvas
          } else {
          }
        }
      });
    },
    clickSearch(val) {
      this.isSearch = val;
    },
    query_shop() {
      let startD = new Date(this.startDate);
      let endD = new Date(this.endDate);
      if (startD.getTime() > endD.getTime()) {
        this.$message.warning("起始时间不能大于结束时间");
        return false;
      }
      this.p++;
      http.get(this, {
        url: "store/index",
        data: {
          token: localStorage.getItem("user_token"),
          searchtype: this.searchtype,
          startDate: this.startDate,
          endDate: this.endDate,
          search: this.search,
          pagesize: 5,
          p: this.p
        },
        dataType: "json",
        success: function(data) {
          if (data.status == 1) {
            let info = data.info;
            if (this.p <= info.total_page) {
              this.shoplist = this.shoplist.concat(info.list);
            }
          } else {
            this.$message.error(data.info);
          }
        }
      });
    },
    // query_shop1(){
    //     this.shoplist = []
    //     http.get(this, {
    //         url: "store/index",
    //         data: {
    //             token: localStorage.getItem("user_token"),
    //             searchtype:this.searchtype,
    //             startDate:this.startDate,
    //             endDate:this.endDate,
    //             search:this.search,
    //             pagesize:5,
    //             p:0
    //         },
    //         dataType: "json",
    //         success: function(data) {
    //             if(data.status == 1){
    //                 this.shoplist = data.info.list
    //             }else{
    //                 this.$message.error(data.info);
    //             }

    //         }
    //     })
    // },
    showDetail(id) {
      http.get(this, {
        url: "/store/detail",
        data: {
          token: localStorage.getItem("user_token"),
          store_id: id
        },
        dataType: "json",
        success: function(data) {
          console.log(data);
          if (data.status == 1) {
            this.item = data.info;
            this.isDetail = true;
          } else {
            this.$message.error(data.info);
          }
        }
      });
    },
    close() {
      this.isDetail = false;
    },
    close1() {
      this.isDetail1 = false;
    },
    storeinfo() {
      http.get(this, {
        url: "store/store_info",
        data: {
          token: localStorage.getItem("user_token")
        },
        dataType: "json",
        success: function(data) {
          console.log("门店信息:", data);
          if (data.status == 1) {
            this.user_info = data.info;
            this.user_type = "store";
            this.store_invite_uid = data.info.store_uid;
            this.user_info.my_invite_code = data.info.store_my_invite_code;
            // this.total_commission = data.info.total_commission;
            // this.store_count = data.info.store_count;
            localStorage.setItem("user_name", data.info.store_name);
            //localStorage.setItem("user_head", data.info.headimgurl);
            localStorage.setItem("user_type", "store");
          } else {
          }
        }
      });
    },
    query_shop2() {
      this.p = 0;
      this.shoplist = [];
      this.query_shop();
    },
    add_shop() {
      this.isDetail1 = true;
    },

    submit() {
      if (this.is_add) {
        if (
          this.formLabel.store_name == "" ||
          this.formLabel.store_mobile == "" ||
          this.formLabel.store_password == ""
        ) {
          this.$message.error("请您填写店铺信息");
          return false;
        }
        this.is_add = false;

        if (!this.formLabel.uid && !this.formLabel.store_id) {
          http.post(this, {
            url: "passport/store_add",
            data: {
              token: localStorage.getItem("user_token"),
              invite_code: this.user_info.my_invite_code,
              store_invite_uid: this.store_invite_uid,
              ...this.formLabel
            },
            dataType: "json",
            success: function(data) {
              console.log(data);
              if (data.status == 1) {
                this.$message.success("添加店铺成功");
                this.isDetail1 = false;
                this.formLabel = {};
                this.query_shop2();
                this.is_add = true;
              } else {
                console.log("-------");
                this.$message.error(data.info);
                this.is_add = true;
              }
            }
          });
        } else {
          http.post(this, {
            url: "passport/store_edit",
            data: {
              token: localStorage.getItem("user_token"),
              ...this.formLabel
            },
            dataType: "json",
            success: function(data) {
              console.log(data);
              if (data.status == 1) {
                this.$message.success("修改店铺成功");
                this.isDetail1 = false;
                this.formLabel = {};
                this.query_shop2();
                this.is_add = true;
              } else {
                console.log("-------");
                this.$message.error(data.info);
                this.is_add = true;
              }
            }
          });
        }
      }
    }
  },
  created() {},
  activated() {
    this.is_add = true;
    this.query_shop();
    let user_type = localStorage.getItem("user_type");
    if (user_type == "store") {
      this.storeinfo();
    } else {
      this.userinfo();
    }
  },
  watch: {
    $route() {
      console.log("监听");
      this.p = 0;
      this.shoplist = [];
      this.query_shop();
    }
  }
};
</script>

<style scoped lang="scss">
.qrcode-wrapper {
}

.top-wrap {
  $letHeight: 1.3rem;

  .title-txt {
    height: $letHeight;
    line-height: $letHeight;
    text-align: center;
    background-color: $c-white-light;

    span {
      color: $c-mainC;
      display: inline-block;
      line-height: $letHeight;
      vertical-align: middle;

      &.title-01 {
        font-size: 0.38rem;
      }
    }
  }
}

.main-wrap {
  @extend .cmm-border;
}

.img-wrap {
  width: 5rem;
  height: 5rem;
  margin: 0.4rem auto;
  overflow: hidden;
  position: relative;
  padding: 0.22rem;

  .ad-img {
    @extend .cmm-translateXY;
    width: 100%;
  }
}

.qrcode-box {
  text-align: center;
  width: 100%;
  .qrcode-txt {
    width: 5.15rem;
    border-radius: 0.8rem;
    background-color: $c-danger;
    font-size: 0.52rem;
    color: $c-white-light;
    $letHeight: 0.6rem;
    height: $letHeight;
    line-height: $letHeight;
    text-align: center;
    margin: 0.48rem auto;
    display: inline-block;
    letter-spacing: 0.1rem;
    font-weight: bold;
  }
}
.title-txt-new {
  height: 1rem;
  line-height: 1rem;
  text-align: center;
  background-color: $c-white-light;
  font-size: 0.32rem;
}
.picker {
  padding: 0 10px;
  border-top: 0.15rem solid #eeeeee;
  font-size: 0.3rem;
  .el-date-editor.el-input,
  .el-date-editor.el-input__inner {
    width: 1.8rem;
  }
  /deep/.el-icon-search {
    font-size: 0.3rem;
  }
}
.timer_box {
  /deep/.el-input__inner {
    border: none;
  }
}
.shop_table_header {
  display: flex;
  line-height: 1rem;
  padding: 0 0.2rem;
  border-bottom: 1px solid #eeeeee;
  & > div.th_one {
    flex: 5;
  }
  & > div.th_two {
    flex: 2;
  }
  & > div.th_three {
    flex: 2;
    text-align: center;
  }
}
.shop_table_table {
  & > li {
    padding: 0.25rem 0.2rem;
    display: flex;
    & > div.td_one {
      flex: 5;
      & > div.td_item_one {
        margin-bottom: 0.2rem;
      }
      & > div.td_item_two {
        & > span {
          font-size: 0.08rem;
        }
      }
    }
    & > div.td_two {
      flex: 2;
      & > div.td_item_one {
        margin-bottom: 0.2rem;
      }
      & > div.td_item_two {
        & > span {
          font-size: 0.08rem;
        }
      }
    }
    & > div.td_three {
      flex: 2;
      display: flex;
      justify-content: center;
      align-items: center;
      i {
        margin: 0 0.05rem;
      }
    }
  }
}
.title_box {
  height: 0.9rem;
  line-height: 0.9rem;
  font-size: 0.36rem;
  text-align: center;
}
.timer_box {
  height: 0.8rem;
  line-height: 0.8rem;
}
.hot-key {
  width: 100%;
  min-height: 6rem;
  span {
    display: inline-block;
    width: 30%;
    height: 0.5rem;
    line-height: 0.5rem;

    text-align: center;
    font-size: 0.32rem;
    margin: 0.1rem 0;
    margin-right: 0.12rem;
    background-color: $c-gray-dark;
    color: $c-mainC;
    border-radius: 0.06rem;
  }
}
.shop_detail {
  position: relative;
  .shop_name {
    height: 1rem;
    line-height: 1rem;
    padding: 0 0.4rem;

    font-size: 0.3rem;
  }
  .shop_other_box {
    border-bottom: 0.013333rem solid #eeeeee;
    border-top: 0.013333rem solid #eeeeee;
  }
  .shop_other {
    height: 0.8rem;
    line-height: 0.8rem;
    padding: 0 0.4rem;
  }
  .shop_price {
    height: 4rem;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.32rem;
    color: #c09a5b;
  }
}
.select_query {
  /deep/.el-input-group__prepend {
    width: 1.6rem;
  }
  /deep/.el-input-group__append {
    width: 1rem;
    text-align: center;
  }
  /deep/.input-with-select {
    height: 0.8rem;
  }
  /deep/.el-input__inner {
    height: 0.8rem;
  }
}
.shop_box {
  min-height: 6rem;
  position: relative;
}
.slide-fade-enter-active {
  transition: all 0.3s ease;
}
.slide-fade-leave-active {
  transition: all 0.8s cubic-bezier(1, 0.5, 0.8, 1);
}
.slide-fade-enter, .slide-fade-leave-to
        /* .slide-fade-leave-active for below version 2.1.8 */ {
  transform: translateX(-100%);
  opacity: 0;
}
.shop_close {
  position: absolute;
  right: 0.3rem;
  top: 0.32rem;
  font-size: 0.32rem;
}
.shop_detail {
  position: relative;
  .shop_name {
    height: 1rem;
    line-height: 1rem;
    padding: 0 0.4rem;

    font-size: 0.3rem;
  }
  .shop_other_box {
    border-bottom: 0.013333rem solid #eeeeee;
    border-top: 0.013333rem solid #eeeeee;
  }
  .shop_other {
    height: 0.8rem;
    line-height: 0.8rem;
    padding: 0 0.4rem;
  }
  .shop_price {
    height: 4rem;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.32rem;
    color: #c09a5b;
  }
}
.select_query {
  /deep/.el-input-group__prepend {
    width: 1.6rem;
  }
  /deep/.el-input-group__append {
    width: 1rem;
    text-align: center;
  }
  /deep/.input-with-select {
    height: 0.8rem;
  }
  /deep/.el-input__inner {
    height: 0.8rem;
    max-width: 7rem;
  }
}
.shop_box {
  min-height: 6rem;
  position: relative;
}
.slide-fade-enter-active {
  transition: all 0.3s ease;
}
.slide-fade-leave-active {
  transition: all 0.8s cubic-bezier(1, 0.5, 0.8, 1);
}
.slide-fade-enter, .slide-fade-leave-to
        /* .slide-fade-leave-active for below version 2.1.8 */ {
  transform: translateX(-100%);
  opacity: 0;
}
.tran_box {
  transform: translateX(-100%);
}
.shop_close {
  position: absolute;
  right: 0.3rem;
  top: 0.32rem;
  font-size: 0.32rem;
}
.add_clerk {
  padding-top: 0.8rem;
  .title {
    font-size: 0.3rem;
    margin-bottom: 0.6rem;
    margin-left: 0.2rem;
  }
  /deep/.el-input__inner {
    border-top: none;
    border-left: none;
    border-right: none;
  }
}
/deep/.el-form-item {
  margin-bottom: 0.4rem;
}
/deep/.el-form-item__label {
  text-align: center;
}
.add_clerk1 {
  padding: 0.8rem 0.25rem 0 0.25rem;
  font-size: 0.24rem;
  border-bottom: 0.01333rem solid #eeeeee;
  & > div {
    margin-bottom: 0.25rem;
  }
}
.custom_box {
  .custom_title {
    height: 1rem;
    line-height: 1rem;
    text-align: center;
    font-size: 0.3rem;
  }
  .custom_ul {
    li {
      width: 25%;
      float: left;
      margin-bottom: 0.2rem;
      & > a {
        margin: 0 0.1rem;
        background-color: #eeeeee;
        display: block;
        line-height: 0.6rem;
        text-align: center;
      }
    }
  }
}
</style>
